package org.algorithm.YaYa.链表;

import org.algorithm.biubiu.wheel_1.common.ListNode;
import org.junit.Test;

/**
 * @Date 2022/2/28
 * @Desc {https://leetcode-cn.com/problems/odd-even-linked-list/submissions/}
 */
public class 奇偶链表 {
    @Test
    public void test(){
        ListNode node = ListNode.build(1,2,3,4,5);
        System.out.println(ListNode.print(oddEvenList(node)));
    }
    public ListNode oddEvenList(ListNode head) {
        if (head == null) {
            return head;
        }
        ListNode evenHead = head.next;
        ListNode odd = head, even = evenHead;
        while (even != null && even.next != null) {
            odd.next = even.next;
            odd = odd.next;
            even.next = odd.next;
            even = even.next;
        }
        odd.next = evenHead;
        return head;
    }
}
